package com.example.smart.base.dialog

import android.content.Context
import android.view.Gravity
import android.view.View
import com.example.lib.extend.getDeviceWidth
import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.extend.visi
import com.example.smart.R
import com.example.smart.base.dialog.base.BaseDialog
import com.example.smart.databinding.DialogSureBinding

class SureDialog(context: Context) :
    BaseDialog<DialogSureBinding>(
        width = ((getDeviceWidth(context) * 0.77).toInt()),
        dialogContext = context,
        gravity = Gravity.CENTER
    ) {
    private var mTitle = ""
    private var mMsg = ""
    private var mOkText = context.getString(com.example.lib.R.string.sure)
    private var mOkTextColor = context.getColor(com.example.lib.R.color.white)
    private var mCancelTextColor = context.getColor(com.example.lib.R.color.blue_4279ff)
    private var success: (SureDialog) -> Unit = {}

    override fun setLayoutRes() = R.layout.dialog_sure

    override fun afterViewCreate(view: View?) {
        banCancel()
        binding.DialogExitTipsDone.setOnDoubleClickListener {
            success.invoke(this@SureDialog)
        }
    }

    fun setDoneListener(success: (SureDialog) -> Unit): SureDialog {
        this.success = success
        return this
    }

    fun setOkText(str: String): SureDialog {
        this.mOkText = str
        return this
    }

    fun setOkTextColor(color: Int): SureDialog {
        this.mOkTextColor = context.getColor(color)
        return this
    }

    fun setCancelTextColor(color: Int): SureDialog {
        this.mCancelTextColor = context.getColor(color)
        return this
    }

    fun setMsg(msg: String): SureDialog {
        this.mMsg = msg
        return this
    }

    fun setTitle(title: String): SureDialog {
        this.mTitle = title
        return this
    }

    override fun show() {
        super.show()
        if (mTitle.isNotEmpty()) {
            binding.DialogTipsTitle.visi()
            binding.DialogTipsTitle.text = mTitle
        }
        binding.DialogTipsMsg.text = mMsg

        binding.DialogExitTipsDone.text = mOkText
        binding.DialogExitTipsDone.setTextColor(mOkTextColor)
    }
}